using Com.HaoJun.Mall.Api.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace Com.HaoJun.Mall.Api.Controllers
{
    public class AdminController : ApiController
    {
        Com.HaoJun.Mall.BLL.AdminUser bll = new BLL.AdminUser();
        [HttpGet]
        public ApiReturnObject<int> Delete(int id = 0)
        {
            ApiReturnObject<int> obj = new ApiReturnObject<int>
            {
                returncode = 0,
                result = 1,
                message = ""
            };
            if(id>0){
            var m = bll.Delete(id);
            if (m)
            {
                obj.result = 0;
                obj.returncode = 0;
            }
            }
           
            return obj;
        }
        [HttpGet]
        public ApiReturnObject<int> Login(string name, string pwd)
        {
            ApiReturnObject<int> obj = new ApiReturnObject<int>();
            var list = bll.GetModelList("UserName='" + name + "'and PassWord='" + pwd + "'");
            if (list.Count > 0)
            {
                HttpCookie cookie = new HttpCookie("AdminUser", name);
                HttpCookie isadmin = new HttpCookie("IsAdmin", pwd);
                HttpContext.Current.Response.Cookies.Add(cookie);
                HttpContext.Current.Response.Cookies.Add(isadmin);
                obj.result = 0;
                obj.returncode = 0;
                obj.message = "登陆成功";
            }
            else{
            {
                obj.result = 1;
                obj.returncode = 0;
                obj.message = "账户或密码错误";
            };
            }
            return obj;
        }
    }
}
